A flash memory apparatus is a non-volatile memory whose storage medium is NAND flash, and has a characteristic that data does not disappear after power-off. Therefore, the flash memory apparatus is widely used as an external memory or an internal memory. A flash memory apparatus that uses the NAND flash as a storage medium may be a solid state disk (SSD for short), which is also called a solid state drive (full name: solid state drive, SSD for short), or may be another memory.
An SSD generally includes multiple flash memory chips, where each flash memory chip includes a plurality of blocks. The NAND flash has an erasability feature. Therefore, unlike data in a common mechanical hard disk, data stored in a block is not directly modified. When data needs to be modified, an idle block for storing modified data needs to be found. Then, the modified data is written into the idle block, and a logical address of the original data is mapped to the modified data. The original data stored in the original block becomes invalid. For an SSD, valid data refers to data that is stored in a block and is mapped to a logical address. The valid data will be read. Invalid data refers to data that is stored in a block and is not mapped to a logical address. The invalid data will not be read.
As data stored in an SSD increases, there are fewer available idle blocks. Therefore, it is necessary to perform garbage collection on the SSD to generate idle blocks. The garbage collection refers to that valid data in a block is moved into an idle block, and the original block is erased, so that the erased block can be written with data as an idle block. Generally, when the garbage collection is performed on the SSD, a block storing a great amount of invalid data may be found. Because the block storing a great amount of invalid data stores a small amount of valid data, data that needs to be moved into an idle block is small. As a lifetime of the SSD is related to a quantity of erasure times of an NAND flash, less data to be moved during garbage collection indicates smaller write amplification of the SSD. However, since the chances that data in different blocks is modified are almost equivalent, there is no obvious difference in amounts of invalid data included in the blocks.